<template>
	<view class="login-content">
		<image class="login-icon" src="/static/images/login_icon.png"></image>
		<view class="title f-30">需要授权登录</view>
		<view class="tip">该功能需要授权登录才可使用，您需要现在授权登录吗</view>
		<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">授权登录</button>    
	</view>

</template>

<script>
	import {
		// mapState,  
		mapMutations
	} from 'vuex';
	import { phoneLogin, getURLParamInfo } from '@/static/js/utils.js'
	export default {
		// computed: {  
		//           ...mapState(['userInfo'])
		//       },
		data() {
			return {
				rurl: '',
				code: '', //微信临时登录凭证
				noAuth: '',
				query: {},
				codeType: ''
			}
		},
		onLoad: function(e) {
			this.codeType = e.type
			this.query = e
			this.noAuth = e.noAuth || ''
			this.rurl = e.rurl ? decodeURIComponent(e.rurl) : ''
			if (e.q) {
				let strArray = decodeURIComponent(e.q)
				this.codeType = getURLParamInfo('type', strArray)
			}
			
		},
		onShow() {
			uni.login({
				success: function(loginRes) {	
				}
			})
		},
		methods: {
			getPhoneNumber: function(e) {
				let that = this
				phoneLogin(e, function(res) {
					// 加了一个二维码扫码落地页，落到登录页 然后一路到企业认证页，做特别判断处理
					if(that.codeType != 'companyAuth') {
						if (res.role == 'user' && !that.noAuth) {
							let urls = `/pages/openWz-step1/index?type=${that.query.type}&id=${that.query.id}&phone=${that.query.phone}`
							uni.navigateTo({
								url:urls
							});
						} else {
							if (that.rurl) {
								if (that.rurl.indexOf('/my/index') > -1 || that.rurl.indexOf('/index/index' ) > -1) {
									uni.reLaunch({
										url: `${that.rurl}?id=${that.query.id}&phone=${that.query.phone}&template_id=${that.query.id}`
									});
								} else {
									uni.redirectTo({
										url: `${that.rurl}?id=${that.query.id}&phone=${that.query.phone}&template_id=${that.query.id}`
									});
								}
							} else {
								uni.reLaunch({
									url: '/pages/index/index'
								});
							}
						}
					} else {
						if (res.role == 'user') {
							uni.redirectTo({
								url: `/pages/openWz-step1/index?type=companyAuth`
							});
							return false
						} else if (res.role == 'real_user') {
							uni.redirectTo({
							    url: `/pages/companyAuth/index`
							})
							return false
						} else {
							uni.reLaunch({
								url: '/pages/index/index'
							});
						}
					}
					
				}, function(){})
			},
			/**
			 * 检测广告轮播图滚动
			 */
			handleChange(e) {
				this.current = e.detail.current
			},
			///...mapMutations(['login']),
			
		},


	}
</script>

<style lang="scss" scoped>
	.login-content {
		position: absolute;
		width: 568rpx;
		background-color: #FFFFFF;
		left: 50%;
		margin-left: -284rpx;
		top: 14%;
		z-index: 9;
		padding: 76rpx 60rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
		text-align: center;
		.login-icon {
			width: 182rpx;
			height: 123rpx;
			margin: 0 auto 45rpx auto;
		}
		.title {
			font-weight: bold;
		}
		.tip {
			margin-top: 16rpx;
			color: #666666;
		}
		button {
			width: 365rpx;
			height: 80rpx;
			margin-top: 68rpx;
			background: #0579FE;
			box-shadow: 0px 6rpx 16rpx 0rpx rgba(5, 121, 254, 0.4);
			border-radius: 47rpx;
			color: #FFFFFF;
			line-height: 80rpx;
			font-size: 32rpx;
		}
		.login-close {
			position: absolute;
			width: 48rpx;
			height: 48rpx;
			right: 16rpx;
			top: 16rpx;
			z-index: 9;
		}
	}
</style>